package com.hmall.user.interceptor;

import com.hmall.common.util.ThreadLocalUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Interceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String authorization = request.getHeader("authorization");
        if (StringUtils.isNotBlank(authorization))
            ThreadLocalUtil.setUserId(Long.parseLong(authorization));
        return HandlerInterceptor.super.preHandle(request, response, handler);
    }
}
